public class Main {

    //字符修改
    public static void main(String[] args) {
        String s = "hello";
        s += "world";
        System.out.println(s);
    }

    public static void main20(String[] args) {
        String str = "  HeLlo%$$%@#$%world 哈哈哈";
        System.out.println(str);
        System.out.println(str.toUpperCase());
        System.out.println(str.toLowerCase());
    }
    public static void main19(String[] args) {
        String str = "      hello world ";
        System.out.println("["+str+"]");
        System.out.println("["+str.trim()+"]");

    }
    public static void main18(String[] args) {
        String str = "helloworld";
        System.out.println(str.substring(6));
        System.out.println(str.substring(0,5));
    }
    //多次拆分
    public static void main17(String[] args) {
        String str = "name=zhangsan&age=18";
        String[] result = str.split("&");
        for (int i = 0; i < result.length; i++) {
            String[] temp = result[i].split("=");
            System.out.println(temp[0]+"="+temp[1]);
        }
    }

    //拆分IP地址
    public static void main16(String[] args) {
        String str = "192.168.1.1";
        String[] result = str.split("\\.");
        for (String s:result) {
            System.out.println(s);
        }
    }

    //字符串不封拆分
    public static void main15(String[] args) {
        String str = "hello world hello Vinson";
        String[] result = str.split(" ",2);
        for (String s:result) {
            System.out.println(s);
        }
    }
    //字符串拆分
    public static void main14(String[] args) {
        String str = "hello world hello code";
        String[] result = str.split(" ");//按照空格拆分；
        for (String s:result) {
            System.out.println(s);
        }
    }
    //字符串替换
    public static void main13(String[] args) {
        String str = "helloworld";
        System.out.println(str.replaceAll("l","666"));
        System.out.println(str.replaceFirst("l","666"));

    }
    //格式化
    public static void main12(String[] args) {
        String s = String.format("%d-----%d-----%d",2019,9,14);
        System.out.println(s);
    }

    //字符串转数组
    public static void main11(String[] args) {
        String s = "hello";
        char[] ch = s.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch[i]);
        }
        System.out.println();
        //数组转字符串
        String s2 = new String(ch);
        System.out.println(s2);

    }


    //大小写转换
    public static void main10(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        String s3 = "HELLOworld";

        //小写转大写
        System.out.println(s1.toUpperCase());
        System.out.println(s2.toUpperCase());
        System.out.println(s3.toUpperCase());
        System.out.println(s3);
    }

    public static void main9(String[] args) {
       String s1 = String.valueOf(1234);
       String s2 = String.valueOf(12.34);
       String s3 = String.valueOf(true);
//       String s4 = String.valueOf(new Student("hanmeimei",18));
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
//        System.out.println(s4);
        System.out.println("==================");
        //字符转数字
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);

    }
    //转化

    public static void main8(String[] args) {
        String s = "aaabbbcccaaabbbccc";
        System.out.println(s.charAt(3));   //b
        System.out.println(s.indexOf('c'));  //  6
        System.out.println(s.indexOf('c',10));  //
        System.out.println(s.indexOf("bbb"));
        System.out.println(s.indexOf("bbb",10));
        System.out.println(s.lastIndexOf('c'));
        System.out.println(s.lastIndexOf('c',10));
        System.out.println(s.lastIndexOf("bbb"));
        System.out.println(s.lastIndexOf("bbb",10));
    }


    public static void main7(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("ABc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareToIgnoreCase(s2));
        System.out.println(s1.compareToIgnoreCase(s3));
        System.out.println(s1.compareToIgnoreCase(s4));

    }
    public static void main6(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("abc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareToIgnoreCase(s2));
        System.out.println(s1.compareToIgnoreCase(s3));
        System.out.println(s1.compareToIgnoreCase(s4));
    }
    public static void main5(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("abc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareTo(s3));
        System.out.println(s1.compareTo(s4));
    }



    //equals比较字符
    public boolean equals(Object anObject) {
        char[] value = new char[10];

// 1. 先检测this 和 anObject 是否为同一个对象比较，如果是返回true
        if (this == anObject) {
            return true;
        }
// 2. 检测anObject是否为String类型的对象，如果是继续比较，否则返回false
        if (anObject instanceof String) {
// 将anObject向下转型为String类型对象
            String anotherString = (String) anObject;
            int n = value.length;
// 3. this和anObject两个字符串的长度是否相同，是继续比较，否则返回false
            if (n == anotherString.length()) {
                char v1[] = value;
                char v2[] = anotherString.toCharArray();
                // 是这么写的，不是你刚才的那种写法哈， 你看看还有其他问题吗
                int i = 0;
// 4. 按照字典序，从前往后逐个字符进行比较
                while (n-- != 0) {
                    if (v1[i] != v2[i])
                        return false;
                    i++;
                }
                return true;
            }
        }
        return false;
    }
    public static void main4(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("Hello");
// s1、s2、s3引用的是三个不同对象，因此==比较结果全部为false
        System.out.println(s1 == s2); // false
        System.out.println(s1 == s3); // false
// equals比较：String对象中的逐个字符
// 虽然s1与s2引用的不是同一个对象，但是两个对象中放置的内容相同，因此输出true
// s1与s3引用的不是同一个对象，而且两个对象中内容也不同，因此输出false
        System.out.println(s1.equals(s2)); // true
        System.out.println(s1.equals(s3)); // false
    }





    //比较是否引用同一个变量
    public static void main3(String[] args) {
        int a = 10;
        int b = 20;
        int c = 10;
        System.out.println(a == b);
        System.out.println(b == c);
        System.out.println("===============");
        //比较是否引用同一个对象
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");
        String s4 = s1;
        System.out.println(s1 == s2);
        System.out.println(s2 == s3);
        System.out.println(s1 == s4);
    }

    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;

        System.out.println(s1.length());
        System.out.println(s1.isEmpty());

        System.out.println("world".length());
    }

    public static void main1(String[] args) {

        String s1 = "hello world";
        System.out.println(s1);

        String s2 = new String("hello world2");
        System.out.println(s2);

        char[] array = {'h','e','l','l','o','3'};
        System.out.println(array);


    }
}